package com.lottery.game.runner.v2;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;

import lombok.AllArgsConstructor;
import lombok.Data;

public class GameThreadDaemonContext {

	private static final Map<String, ThreadInfo> allThreadInfoMap = new HashMap<String, ThreadInfo>();

	private static Boolean full = false;

	public static void addThread(ExecutorService service, RoomCoreExecutor executor) {
		allThreadInfoMap.put(executor.getThreadName(), new ThreadInfo(service, executor));
	}

	public static void releaseAll() {
		Set<String> all = allThreadInfoMap.keySet();
		for (String key : all) {
			ThreadInfo info = allThreadInfoMap.get(key);
			info.getExecutor().disallow();
			info.getService().shutdown();
		}
		allThreadInfoMap.clear();
	}

	public static void setFull() {
		full = true;
	}

	public static Boolean isFull() {
		return full;
	}

	public static void setEmpty() {
		full = false;
	}

}

@AllArgsConstructor
@Data
class ThreadInfo {
	private ExecutorService service;

	private RoomCoreExecutor executor;
}
